package cn.mldn.homework.multiThreadCountPrime;

public abstract class AbstractFinder
{

	public boolean isPrime(int number)
	{
		if (number <= 1)
			return false;
		for (int i = 2; i <= Math.sqrt(number); i++)
		{
			if (number % i == 0)
				return false;
		}
		return true;
	}

	public int countPrime(int startNumber,int endNumber)
	{
		int num = 0;
		for (int i = startNumber; i <= endNumber; i++)
		{
			if (isPrime(i))
				num++;
		}
		return num;
	}

	public void countPrimeAndTime(int number)
	{
		long startTime = System.nanoTime();
		long num = multiThreadCountPrime(number);
		long endTime = System.nanoTime();
		System.out.printf("%d 内素数个数 : %d\n", number, num);
		System.out.println("并行计算所用时间 : " + (endTime - startTime) / 1.0e9+"秒");
	}

	public abstract int multiThreadCountPrime(int number);
}
